package sma.trabajoFinal.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import sma.trabajoFinal.util.UtilJPA;

@Entity
@Table(name = "Factura")
@XmlRootElement
public class Factura implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@Basic(optional = false)
	@Column(name = "idFactura")
	private Integer idFactura;

	@Column(name = "numero")
	private String numero;

	@Column(name = "cliente")
	private Integer cliente;

	/**
	 * 
	 */
	public void insertar() {
		try {

			FacturaJpaController facturaController = new FacturaJpaController(
					UtilJPA.getEntityManagerFactory());

			facturaController.create(this);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 */
	public void modificar() {
		try {

			FacturaJpaController facturaController = new FacturaJpaController(
					UtilJPA.getEntityManagerFactory());

			facturaController.edit(this);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 */
	public void borrar() {
		try {

			FacturaJpaController facturaController = new FacturaJpaController(
					UtilJPA.getEntityManagerFactory());

			facturaController.destroy(this);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 
	 */
	public List<Factura> buscar() {

		List<Factura> rList = null;

		try {

			FacturaJpaController facturaController = new FacturaJpaController(
					UtilJPA.getEntityManagerFactory());

			rList = facturaController.findFacturaEntities();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return rList;
	}

	/**
	 * 
	 * @return
	 */
	public String getNumero() {
		return numero;
	}

	/**
	 * 
	 * @param numero
	 */
	public void setNumero(String numero) {
		this.numero = numero;
	}

	/**
	 * 
	 * @return
	 */
	public Integer getIdFactura() {
		return idFactura;
	}

	/**
	 * 
	 * @param idFactura
	 */
	public void setIdFactura(Integer idFactura) {
		this.idFactura = idFactura;
	}

	/**
	 * 
	 * @return
	 */
	public Integer getCliente() {
		return cliente;
	}

	/**
	 * 
	 * @param cliente
	 */
	public void setCliente(Integer cliente) {
		this.cliente = cliente;
	}

}
